package com.liziba.es;

import com.liziba.es.util.ElasticsearchUtil;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @auther LiZiBa
 * @date 2021/2/25 23:23
 * @description: 启动类型
 **/

@SpringBootApplication
public class JDSearchApplication {

    /**
     * 索引名称
     */
    public static final String INDEX_NAME = "jd_goods";

    public static void main(String[] args) {
        SpringApplication.run(JDSearchApplication.class, args);
    }

    @Resource
    public RestHighLevelClient client;

    /**
     * @PostConstruct修饰的方法会在服务器加载Servlet的时候运行，并且只会被服务器执行一次
     */
    @PostConstruct
    public void initIndex() {
        ElasticsearchUtil elasticsearchUtil = new ElasticsearchUtil(client);
        elasticsearchUtil.createIndex(INDEX_NAME);
    }
}
